/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package questionbook;


import java.util.List;
import questionbook.exception.IndividualAlreadyExistsException;
import questionbook.manager.ReasoningManager;
import questionbook.manager.ReasoningType;
import questionbook.model.Answer;
import questionbook.model.Category;
import questionbook.model.Comment;
import questionbook.model.Person;
import questionbook.model.Question;
import questionbook.model.Suggest;
import questionbook.service.AnswerService;
import questionbook.service.AnswerServiceBean;
import questionbook.service.CategoryService;
import questionbook.service.CategoryServiceBean;
import questionbook.service.CommentService;
import questionbook.service.CommentServiceBean;
import questionbook.service.FriendshipService;
import questionbook.service.FriendshipServiceBean;
import questionbook.service.PersonService;
import questionbook.service.PersonServiceBean;
import questionbook.service.QuestionService;
import questionbook.service.QuestionServiceBean;
import questionbook.service.SuggestService;
import questionbook.service.SuggestServiceBean;
import questionbook.standard.Qbook;

/**
 *
 * @author stefanstift
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

//        try {

             PersonService personService = new PersonServiceBean();
             QuestionService questionService = new QuestionServiceBean();
             CategoryService categoryService =  new CategoryServiceBean();
             AnswerService answerService = new  AnswerServiceBean();
             CommentService commentService = new CommentServiceBean();
             SuggestService suggestService = new SuggestServiceBean();
             FriendshipService friendshipService = new FriendshipServiceBean();

//             ReasoningManager.getInstance().processReasoning(ReasoningType.Classes);


             Person peter = personService.authenticate("peter.kogler@aon.at", "fuxi");
             Person franz = personService.authenticate("franz.pizek@gmail.com", "hallo");

             System.out.println("Peter = " + peter.getFirstName() + " " + peter.getMbox() + " " + peter.getUserClass());
             System.out.println("franz = " + franz.getFirstName() + " " +  franz.getMbox() + " " + franz.getUserClass());

             List<Question> questions = questionService.getAll();

             for(Question q : questions)
             {
                 System.out.println("q gefunden => " + q.getText() + " - " + q.getUri().stringValue());
             }


             Question wanted = questions.get(7);

             System.out.println(wanted.getText());

             List<Question> link = questionService.getLinkedQuestions(wanted);

             for(Question q1  : link)
             {
                 System.out.println("link gefunden => " + q1.getText() + " - " + q1.getUri().stringValue()
                           + " cat = " + q1.getCategory().getName() + " title = " + q1.getTitle() + " asker = " + q1.getAsker().getName());
             }




//             questionService.linkQuestions(qL.get(0), qL.get(1));
//             questionService.flush();

//             List<Question> relatedQuestions = questionService.getLinkedQuestions(qL.get(1));

//             for(Question qt : relatedQuestions)
//             {
////                 System.out.println("related " + qt.getUri() + " text = " + qt.getText() + " cat = " + qt.getCategory());
//
//                 System.out.println("REALTED Questioner = " + qt.getAsker().getFirstName() + " Category = " + qt.getCategory().getName() + " Text = " + qt.getText());
//             }

//             questionService.unlinkQuestions(qL.get(1), qL.get(0));
//             questionService.flush();

//             Answer a = answerService.getIdentifiedAnswer();
//             a.setAnswerer(franz);
//             a.setText("na a papier is gscheiter");
//             a.setAnswerType(Qbook.getInstance().getAnswerTypes().get(1));
//
//             answerService.answer(a, qL.get(0));
//
//             answerService.flush();

//             ReasoningManager.getInstance().processReasoning();

//             List<Answer> aL = answerService.getByQuestion(qL.get(0));
//
//             for(Answer at :  aL)
//             {
//                 System.out.println("Answer = " + at.getUri().stringValue() + " Answerer = " + at.getAnswerer().getFirstName() + " Text = " + at.getText()
//                         + " type = " + at.getAnswerType().getUri().stringValue() + " class = " + at.getAnswerClass());
//
//             }



//
//             System.out.println("suggest: ");
//
//             List<Person> suggestList = personService.suggestUsers(categoryService.getAll().get(0));

//              List<Person> suggestList = personService.getAll();

//             for(Person sug : suggestList)
//             {
//                 System.out.println("Person = " + sug.getFirstName() + " " + sug.getMbox());
//             }

//             Suggest s = suggestService.getIdentifiedSuggest();
//             s.setSuggester(peter);
//             s.setSuggested(franz);
//             s.setQuestion(qL.get(0));
//             s.setText("der weiß das sicherlichhh");
//             suggestService.persist(s);
//             suggestService.flush();

//             System.out.println("Man Sugg");
//             List<Suggest> mansuggList = suggestService.getByQuestion(qL.get(0));
//
//             for(Suggest manSugg: mansuggList)
//             {
//                 System.out.println("Suggester = " + manSugg.getSuggester().getFirstName() + " Suggested = " + manSugg.getSuggested().getFirstName() +
//                                    " Wuestion = " + manSugg.getQuestion().getText() + " begrunündung = " + manSugg.getText());
//             }

//             ReasoningManager.getInstance().classify(aL.get(0));
//             ReasoningManager.getInstance().classify(franz);

//             suggestService.delete(mansuggList.get(0));
//             suggestService.flush();
//
//        } catch (IndividualAlreadyExistsException ex) {
//            ex.printStackTrace();
//        }
    }

}
